/*
 * PratamaWijaya.com
 * set.mnemonix@gmail.com
 * States_Logo.java
 * AndEngineGamePanjatPinang
 * 6:54:49 PM 2012
 */

package com.amikomgamedev.panjatpinang.states;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.util.FPSLogger;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.util.color.Color;

import android.content.Intent;

import com.amikomgamedev.panjatpinang.Config;
import com.amikomgamedev.panjatpinang.Data;
import com.amikomgamedev.panjatpinang.Define;

import com.heyzap.sdk.HeyzapLib;

public class State_Logo extends SimpleBaseGameActivity implements Define {

	private Camera				mCamera;
	private Scene				mScene;

	private BitmapTextureAtlas	TexLogo;
	private ITextureRegion		TreLogo;
	private Sprite				SprLogo;

	@Override
	public EngineOptions onCreateEngineOptions() {
		// TODO Auto-generated method stub
		// Game.appInit();
		mCamera = new Camera(0, 0, GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT);
		EngineOptions en = new EngineOptions(true,
				ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(
						GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT), mCamera);
		// load heyzap libs
		HeyzapLib.load(this);
		return en;

	}

	@Override
	protected void onCreateResources() {
		// TODO Auto-generated method stub
		TexLogo = new BitmapTextureAtlas(this.getTextureManager(),
				Data.LOGO_TEX_WIDTH, Data.LOGO_TEX_HEIGHT);
		TreLogo = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				TexLogo, this, Data.IMG_AGD_LOGO_LOCATION, 0, 0);
		TexLogo.load();

	}

	@Override
	protected Scene onCreateScene() {
		// TODO Auto-generated method stub
		mEngine.registerUpdateHandler(new FPSLogger());
		mScene = new Scene();
		mScene.setBackground(new Background(Color.WHITE));

		float centerX = (GAME_SCREEN_WIDTH >> 1) - (TreLogo.getWidth() * 0.5f);
		float centerY = (GAME_SCREEN_HEIGHT >> 1)
				- (TreLogo.getHeight() * 0.5f);

		SprLogo = new Sprite(centerX, centerY, TreLogo,
				new VertexBufferObjectManager());

		mScene.attachChild(SprLogo);

		mEngine.registerUpdateHandler(new TimerHandler(Config.LOGO_DURATION,
				new ITimerCallback() {

					@Override
					public void onTimePassed(TimerHandler pTimerHandler) {
						// TODO Auto-generated method stub

						Intent ucapan = new Intent(State_Logo.this,
								State_Ucapan.class);
						startActivity(ucapan);
						finish();
					}
				}));

		return mScene;
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		HeyzapLib.onActivityResult(requestCode, resultCode, data);
		super.onActivityResult(requestCode, resultCode, data);
	}

}
